package org.association.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;
import org.association.entity.OrgUserStats;
import org.association.entity.OrganizationEntity;
import java.util.List;

@Mapper
public interface OrganizationDao extends BaseMapper<OrganizationEntity> {

    @Insert("INSERT INTO org_user(org_id, private_key) values(#{organizationID}, #{privateKey})")
    boolean addMember(@Param("organizationID") Integer organizationID, @Param("privateKey") String privateKey);

    // 根据用户ID和协会ID查询会员
    @Select("SELECT EXISTS(SELECT 1 FROM org_user WHERE private_key=#{privateKey})")
    boolean userOrgExist(@Param("privateKey") String privateKey);

    @Delete("delete from org_user where org_id = #{organizationID} and private_key = #{privateKey}")
    int quitMember(Integer organizationID, String privateKey);

    @Select("SELECT org_id FROM org_user WHERE private_key=#{privateKey} limit 1")
    Integer getOrgIdByPrimaryKey(String primaryKey);

    @Select("SELECT DISTINCT private_key FROM org_user WHERE org_id=#{organizationID}")
    List<String> getUsersByOrganizationID(@Param("organizationID") Integer organizationID);

    List<OrgUserStats> getOrgUserStats();

    @Select("select address from organization where id = #{organizationId}")
    String getAddressFromOrgId(@Param("organizationId") Integer organizationId);
}
